function exchange_field(form,fields)
{
	//var fields = ["no_srt","tgl_srt","id_afiliasi","to","to_attn","to_address","to_telp","to_fax","to_email","from","from_attn","from_address","from_telp","from_fax","from_email","subject","name","subject_oi","description_og","importer","importer_attn","importer_address","importer_telp","importer_fax","importer_email","exporter","exporter_attn","exporter_address","exporter_telp","exporter_fax","exporter_email","place_oi","date_oi","import_permit_no","invoice_no","quotation_no","quotation_date","company_name","company_npwp","company_address","regard","applicants_name"];
	//var data = {};
	
	//console.log(data)
	//var frm = template(r,data);

	//$(form).find('.form-div').append(r);
	$.each(fields,function(i,field){
		var el = $(form).find('div#'+field+'_field_box');
		var input = el.find('#field-'+field);
		//console.log(input)
		var tpl = $(form).find('#tpl_'+field);
		tpl.replaceWith(input);
		//console.log(tpl)
		el.hide();
	});
}

function template(str, data) {
    var o = data;
    return str.replace(/\{\{(.*?)\}\}/g, function (match, token) {
        return eval("o." + token);
    });
}


$(document).ready(function() {

	$("body").on({
		click:function(){

			var url = $(this).prop('href');
   			var dlg = $('<div id="upwdlg"></div>');
   			var cnt = '<div class="pengguna-password">'+
				'<div>'+
					'<label style="display: block; width: 87px; float: left; line-height: 22px;">New Password :</label>'+
					'<input style="float:left;margin-top:1px;" type="password" name="pengguna_password"/>' +
				'</div><div><input  style="float:left;cursor:pointer;margin-left:2px" type="button" value="Change" class="cmd_set_passwd"/></div>' +
			'</div>';
			var dlg_title = 'Change Password - ' + $.trim($(this).parent().parent().prev().prev().text());
			dlg.html(cnt).dialog({
				modal:true,
				title:dlg_title,
				width:358,
				height:80,
				close:function(){
					dlg.remove();
				}
			});
			
			dlg.find('input.cmd_set_passwd').click(function(){
				var new_passwd = dlg.find('input[name=pengguna_password]').val();
				if(!new_passwd.length){
					alert('Password Anda kosong !')
					return;
				}

				
				$.post(url,{passwd:new_passwd},function(o){
					alert(o.m);
					if(o.s)
						dlg.dialog('close')	;
					else
						$('input[name=pengguna_password]').val('').focus();

				},'json');	
			})
			dlg.find('input[name=pengguna_password]').keydown(function(e){
				if(e.keyCode==13){
					dlg.find('input.cmd_set_passwd').click();
				}
			});
			dlg.dialog('open');
   			
			return false;
    	},
		mouseover:function(){	$(this).prop('title','Ubah Password');}
	},'.grd-user a.pengguna_password_cmd');

});